package org.spring.springboot.pojo.req;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public  class XmlParam {
	
	 /**
	  * ʵ���Զ���XML
	  * @return
	  */
	 public String toXML() {
		
		// �õ�����
		Class<?> clz = this.getClass();
		// ��ȡʵ������������ԣ�����Field����
		Field[] fields = clz.getDeclaredFields();
        String result = "";
        
		for (Field field : fields) {// --for() begin
			String name = field.getName();
			Object value = getFieldValueByName(name,this);
			if(null!=value) {
				result+="<"+name+">"+value+"</"+name+">";
			}
		}
		return result;
	 };
	 /** 
	  * ������������ȡ����ֵ 
	  * */  
	    private Object getFieldValueByName(String fieldName, Object o) {  
	        try {    
	            String firstLetter = fieldName.substring(0, 1).toUpperCase();    
	            String getter = "get" + firstLetter + fieldName.substring(1);    
	            Method method = o.getClass().getMethod(getter, new Class[] {});    
	            Object value = method.invoke(o, new Object[] {});    
	            return value;    
	        } catch (Exception e) {    
//	            log.error(e.getMessage(),e);    
	            return null;    
	        }    
	    }   
}
